Skip to content

Require a descendant directory for a terminal star run like d/***/ - #189

Merged
cpburnz merged 2 commits into
cpburnz:masterfrom
zzoraemon043:fix/star-run-dir-globstar
Dec 3, 2026
Merged

cpburnz merged 2 commits into
cpburnz:masterfrom
zzoraemon043:fix/star-run-dir-globstar

Conversation

@zzoraemon043

Copy link
Copy Markdown
Contributor

d/**/ only matches directories below d (#164), but d/***/ still matches d/ and its direct files, even though #167 made a run of three or more asterisks a globstar:

>>> spec = GitIgnoreSpec.from_lines(['d/***/'])
>>> spec.match_file('d/'), spec.match_file('d/top.txt'), spec.match_file('d/child/')
(True, True, True)

Git ignores only d/child/ (checked with git check-ignore; same for /d/****/, **/d/***/ and a/**/***/).

requires_dir_descendant looks at the raw segments, where the last one is ***, not **, so the check misses it. It now uses the segments with star runs collapsed, as __normalize_segments() does.

The new test_c cases fail before the change and pass after it; the full test suite passes. I also compared GitIgnoreSpec with git check-ignore on about 55,000 random pattern/path pairs. Before the change every difference was a star-run directory pattern like these; after it they all agree.

@cpburnz
cpburnz merged commit 45fe1e5 into cpburnz:master Dec 3, 2026
@cpburnz

cpburnz commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Thanks for finding and fixing this!

cpburnz added a commit that referenced this pull request Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants